package org.example.struct.array;

/**
 * @author liyishan
 * @date 2023/12/6 11:10
 * @apiNote
 */

public class Test00680ValidPalindrome {


    public static boolean validPalindrome(String s) {
        int low = 0,high = s.length() - 1;
        while (low < high) {
            char c1 = s.charAt(low),c2 = s.charAt(high);
            if(c1 == c2){
                low++;
                high--;
            }else{
                return validPalindrome(s,low + 1,high) || validPalindrome(s,low,high - 1);
            }
        }
        return true;

    }

    public static boolean validPalindrome(String s,int low ,int high){
        for(int i = low,j = high;i < j;i++,j--){
            char c1 = s.charAt(i),c2 = s.charAt(j);
            if(c1!=c2){
                return false;
            }
        }
        return true;
    }


}
